/*
 * Copyright (c) 2005-2008 旭鸣信息
 * All rights reserved. 
 */
/*
 * History:
 *       2007-12-11: Initially created, tangkf.
 */
package com.xteam.db;

import java.util.List;
import java.util.Map;

/**
 * 实现数据库的读写等操作的接口
 * @author tangkf
 */
public interface IBaseDao extends IBasePageDao {

	public static final String	SQL_DELETE	= " DELETE ";
	public static final String	SQL_UPDATE	= " UPDATE ";
	public static final String	SQL_FROM	= " FROM ";
	public static final String	SQL_WHERE	= " WHERE ";
	public static final String	SQL_AND		= " AND ";
	public static final String	SQL_OR		= " OR ";
	public static final String	SQL_IN		= " IN ";
	public static final String	SQL_SELECT	= " SELECT ";
	public static final String	SQL_NOTIN	= " NOT IN ";
	public static final String	SQL_ORDERBY	= " ORDER BY ";
	public static final String	SQL_DESC	= " DESC ";
	public static final String	SQL_LIKE	= " LIKE ";
	public static final String	SQL_GROUPBY	= " GROUP BY ";
	public static final String	SQL_HAVING	= " HAVING ";

	public static final String	SQL_EQUAL	= " = ";
	public static final String	SQL_UNEQUAL	= " != ";
	public static final String	SQL_NOTLIKE	= " not like ";
	public static final String	SQL_EXIST	= " exist ";

	/**
	 * <p>
	 * 执行一个没有返回值的 SQL 语句
	 * </p>
	 * @author tangkf
	 * @param sql
	 */
	public int executeSql(String sql) throws Exception;

	/**
	 * <p>
	 * 执行一个有返回值的SQL语句
	 * </p>
	 * @author tangkf
	 * @param sql
	 * @return
	 */
	public <T> List<T> queryAllSql(String sql) throws Exception;

	/**
	 * <p>
	 * 获取一个指定类型的 数据对象
	 * </p>
	 * @author tangkf
	 * @param clazz
	 * @param id
	 * @return
	 */
	public <O> O getObject(Class<O> clazz, String id) throws Exception;

	/**
	 * <p>
	 * 获取一个指定类型的结果列表
	 * </p>
	 * @author tangkf
	 * @param type 类型
	 * @return 一个该类型的对象列表
	 */
	public <T> List<T> queryAll(Class<T> clazz) throws Exception;

	/**
	 * <p>
	 * 立即执行一个没有返回的HQL语句，立即flush
	 * </p>
	 * @author tangkf
	 * @param hql
	 * @throws Exception
	 */
	public int executeHql(String hql) throws Exception;

	/**
	 * <p>
	 * 返回一个指定的 HQL 语句查询结果的第一个对象
	 * </p>
	 * @author tangkf
	 * @param hql
	 * @return
	 */
	public <T> T getObject(String hql) throws Exception;

	/**
	 * 根据字符串匹配来查询相应结果
	 * @author tnagkf
	 * @param hql 查询语句
	 * @param parametersMap key为自定义的key,value为需要匹配的字符串
	 * @return 根据字符串匹配来查询相应结果
	 */
	public <T> List<T> queryAll(String hql, Map<String, Object> parametersMap) throws Exception;

	/**
	 * 查询一个HQL的结果
	 * @author tangkf
	 * @param hql
	 * @return
	 */
	public <T> List<T> queryAll(String hql) throws Exception;

	/**
	 * 保存一个对象
	 * @author tangkf
	 * @param obj: 要保存的对象
	 */
	public int saveObject(Object obj) throws Exception;

	/**
	 * 保存多个对象
	 * @author tangkf
	 * @param objects
	 */
	public int saveObjects(List<Object> objects) throws Exception;

	/**
	 * 删除一个对象
	 * @author tangkf
	 * @param obj
	 */
	public int delete(Object obj) throws Exception;

	/**
	 * 一次删除多个对象
	 * @author tangkf
	 * @param objects: 将要删除的对象列表
	 */
	public <T> int deleteObjects(List<T> objects) throws Exception;

	/**
	 * 由指定的类型,ID名称和ID值列表删除对象
	 * @author tangkf
	 * @param type
	 * @param idName
	 * @param idValues
	 */
	public <T> int deleteBathById(Class<T> type, String idName, String[] idValues) throws Exception;

	/**
	 * 保存或更新一个对象，这个对象是一个entity包中的类
	 * @author tangkf
	 * @param o: 将要更新的对象
	 */
	public int saveOrUpdateObject(Object o) throws Exception;

	/**
	 * 保存或更新一个对象列表，这个对象是一个entity包中的类
	 * @author tangkf
	 * @param objects: 将要更新的对象列表
	 */
	public int saveOrUpdateObjects(List<Object> objects) throws Exception;

	/**
	 * 更新一个对象
	 * @author tangkf
	 * @param obj: 要更新的对象
	 */
	public int updateObject(Object obj) throws Exception;

	/**
	 * 更新多个对象并且更新之后关闭数据库连接
	 * @author tangkf
	 * @param objects:要更新的对象列表
	 */
	public int updateObjects(List<Object> objects) throws Exception;

	/**
	 * <P>
	 * 返回 指定返回记录数的SQL语句;
	 * </P>
	 * @author 汤垲峰 2009-4-27
	 * @param sql
	 * @return
	 */
	public long countSql(String sql) throws Exception;

	/**
	 * <P>
	 * 返回 指定HQL语句执行返回的记录数
	 * </P>
	 * @author 汤垲峰 2009-4-27
	 * @param hql
	 * @return
	 */
	public long countHql(String hql) throws Exception;

	/**
	 * 执行一批HQL语句，执行完成后立即 flush
	 * @author 汤垲峰 2009-12-27
	 * @param hql
	 * @return
	 */
	public int executeBatchHql(String[] hqls) throws Exception;

	/**
	 * 批量执行SQL语句，批量执行完成后立即 flush
	 * @author 汤垲峰 2009-12-27
	 * @param sqls
	 * @return
	 */
	public int executeBatchSql(String[] sqls) throws Exception;

	/**
	 * 执行指定了条件MAP的SQL语句
	 * @author 汤垲峰 2009-12-27
	 * @param sql
	 * @param parms
	 * @return
	 */
	public <T> List<T> queryAllSql(String sql, Map<String, Object> parms) throws Exception;

	/**
	 * 执行HQL语句，并传入参数表
	 * @author tangkf ---2012-1-13
	 * @param hql
	 * @param params
	 * @return
	 */
	public int executeHql(String hql, Object[] params) throws Exception;

	/**
	 * 执行指定了条件参数的SQL语句，参数采用 字符串作为 占位符
	 * @author 汤垲峰 2009-12-27
	 * @param sql
	 * @param parms
	 * @return
	 */
	public <T> List<T> queryAllSql(String sql, Object[] params) throws Exception;

	/**
	 * 由条件参数HQL语句查询结果
	 */
	public <T> List<T> queryAll(String hql, Object[] params) throws Exception;

	/**
	 * 执行SQL语句，并传入参数表
	 * @author tangkf ---2012-1-13
	 * @param sql
	 * @param params
	 * @return
	 */
	public int executeSql(String sql, Object[] params) throws Exception;

	/**
	 * 执行HQL语句，并传入参数表
	 * @author tangkf ---2012-1-13
	 * @param hql
	 * @param params
	 * @return
	 */
	public int executeHql(String hql, Map<String, Object> params) throws Exception;
}
